package net.mlike.openssp.server.search.system.menu;

import com.google.common.base.Strings;
import net.mlike.openssp.server.entity.system.Menu;
import net.mlike.openssp.server.search.BaseSearch;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.Path;

/**
 * Created by wallellen@hotmail.com on 5/26/18.
 */
public class MenuSearch extends BaseSearch {
    private String type;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    protected Specification buildCondition() {
        return (Specification) (root, query, cb) -> {
            if (Strings.isNullOrEmpty(type)) {
                return null;
            }

            Path path = root.get("type");
            return cb.equal(path, Menu.Type.valueOf(type));
        };
    }
}
